package com.aerozhonghuan.logisticsmall.framework.hybrid.actions;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.aerozhonghuan.logisticsmall.framework.hybrid.NewWebviewFragment;
import com.aerozhonghuan.logisticsmall.framework.hybrid.SimpleActionHandler;
import com.aerozhonghuan.logisticsmall.framework.hybrid.bean.JsMobileAgentConstants;
import com.aerozhonghuan.foundation.umeng.UmengAgent;
import com.aerozhonghuan.hybrid.XJsCallback;
import org.json.JSONObject;

/**
 * 描述
 * 作者 Zhang Yonghui
 * 创建日期 2019/1/21
 */
public class UmengEventActionHandler extends SimpleActionHandler {
    private static final String KEY_EVENTNAME = "eventName";
    private static final String KEY_EVENTID = "eventId";

    public UmengEventActionHandler(NewWebviewFragment fragment) {
        super(JsMobileAgentConstants.FLAG_UMENGEVENT, fragment);
    }

    @Override
    public void handleAction(@NonNull String action, @Nullable JSONObject params, @Nullable XJsCallback callBack) {
        if (params == null) {
            return;
        }
        String eventName = params.optString(KEY_EVENTNAME);
        String eventId = params.optString(KEY_EVENTID);
        UmengAgent.onEvent(getActivity(), eventId, eventName);
    }
}
